package com.ia.aistream.service.system.impl;

import com.ia.aistream.manager.authen.ITokenManager;
import com.ia.aistream.manager.authen.token.UserLoginToken;
import com.ia.aistream.model.system.dto.OpenTokenDto;
import com.ia.aistream.service.system.IOpenLoginService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Author: xiaoyu
 * Date: 2020/12/5 15:49
 */
@Service
public class OpenLoginService implements IOpenLoginService {

    @Autowired
    private ITokenManager tokenManager;
    @Override
    public OpenTokenDto login(UserLoginToken token) {
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        return tokenManager.generateUserToken(token.getTokenFrom(),token.getTokenId());
    }
}
